package cz.muni.fi.pv168.confusinglibrary.libs;

import java.util.Date;

public class Book {

    private Long id;
    private Author author;
    private String name;
    private String description;
    private boolean fiction;
    private Date published;

    public Book() {
    }

    public Book(Long id, Author author, String name, String description, boolean fiction, Date published) {
        this.id = id;
        this.author = author;
        this.setName(name);
        this.description = description;
        this.fiction = fiction;
        this.published = published;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return id;
    }

    public void setAuthor(Author author) {
        this.author = author;
    }

    public Author getAuthor() {
        return author;
    }

    public void setName(String name) {
        if (name == null || "".equals(name)) {
            throw new IllegalArgumentException("Null or empty name.");
        }
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    public void setFiction(boolean fiction) {
        this.fiction = fiction;
    }

    public boolean isFiction() {
        return fiction;
    }

    public void setPublished(Date published) {
        this.published = published;
    }

    public Date getPublished() {
        return published;
    }
    
    @Override
    public boolean equals(Object obj){
        if (!(obj instanceof Book)){
            return false;
        }
        Book other = (Book) obj;

        if (other.getId() == null || this.getId() == null){
            return false;
        }

        return this.getId().equals(other.getId());
    }

    @Override
    public int hashCode(){
        return this.getId().hashCode();
    }
}
